
#pragma once

#include <sockets/tls.hpp>
#include <websocketpp.hpp>
//#include <ConnectionBroker/server/WebSocketServerHandler.h>
#include <ConnectionBroker/clientconnection/ClientConnection.h>
#include <boost/shared_ptr.hpp>

namespace ConnectionBroker
{
   template <typename endpoint_type>
   class WebSocketClientConnection : public ClientConnection
   {
      protected: //Member variables
      typename endpoint_type::handler::connection_ptr mConnection;

      public: //Constructor, destructor
      WebSocketClientConnection(typename endpoint_type::handler::connection_ptr pConnection)
      :  ClientConnection(), mConnection(pConnection)
      {
      }
      virtual ~WebSocketClientConnection() {}

      public: //Interface
      virtual void write(const Packet& pPacket)
      {
         //Convert json message to a string.
         std::string msg(PacketUtils::packetToString(pPacket));

         //std::cout << "SENDING" << msg << std::endl;
         //Send the message.
         mConnection->send(msg);
      }

   }; 
}

